package com.java.tutorials.apache.common.beanutils;

import org.apache.commons.beanutils.BeanUtils;

import java.util.Map;
/**
 * Created by xuzhike on 2016/3/5.
 * http://www.java2s.com/Code/Java/Apache-Common/BeanUtilsdealwithcollections.htm
 * Bean Utils: deal with collections
 */
public class BeanUtilsExampleV3 {
    public static void main(String args[]) throws Exception {
        BeanUtilsExampleV3 diff = new BeanUtilsExampleV3();
        Actor actor = diff.prepareData();

        Map describedData = BeanUtils.describe(actor);

        // check the map
        System.err.println(describedData.get("name"));

        // change this value
        describedData.put("name", "Robert Redford");

        // create a new Actor Bean
        Actor newActor = new Actor();
        BeanUtils.populate(newActor, describedData);

        System.err.println(BeanUtils.getProperty(newActor, "name"));

    }

    private Actor prepareData() {
        Actor actor = new Actor();
        actor.setName("Michael Caine");
        actor.setGender(1);
        actor.setWorth(10000000);
        return actor;
    }
}
